/* ----------------------------------------------------------------------------
* File: chat_info_module_impl.h
*
* Desc: Module for getting chat info
*
* Created: 05/05/2011, by Alexey Korshunov
* ---------------------------------------------------------------------------- */
#ifndef _CHAT_INFO_MODULE_IMPL_H_
#define _CHAT_INFO_MODULE_IMPL_H_

#include "exception.h"
#include "utils.h"
#include "chat_info_module.h"
#include "instance_manager.h"

#include <atlbase.h>
#include <atlcom.h>

#import "Skype4COM.dll" named_guids


namespace ModuleManagement
{
	class ModuleChatInfoImpl : public ChatInfoModule
	{
	public:
		ModuleChatInfoImpl() throw(Common::Exception);
		~ModuleChatInfoImpl();

		void Init(const ChatInfoModuleParams& params) throw(Common::Exception);

		// Module implementation
		virtual Common::Error Start(void* param = NULL, size_t size = 0);
		virtual Common::Error Stop(void* param = NULL, size_t size = 0);

	private:
		static DWORD WINAPI ThreadFunc(LPVOID lpParam);
		Common::Error DisplayChatNames();
		SKYPE4COMLib::IChatPtr DetectChat();
		bool IsNecessaryChat(SKYPE4COMLib::IChatPtr pChat);
		void CreateSyncObjects() throw(Common::Exception);
		void DestroySyncObjects();
		void StopThread();

		HANDLE m_Thread;
		HANDLE StartEvent;
		HANDLE StopEvent;
		std::auto_ptr<SkypeProxyManagement::SkypeProxy> m_SkypeProxy;
		SKYPE4COMLib::ISkypePtr m_SkypeInstance;
	};
}

#endif // _CHAT_INFO_MODULE_IMPL_H_
